package com.wxy.feiteng.blog02.controller.admin;
import com.wxy.feiteng.blog02.entity.People;
import com.wxy.feiteng.blog02.service.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
@RequestMapping("/admin")
public class PeopleController {
    @Autowired
    public PeopleService peopleService;

    @RequestMapping("/loginPage")
    public String loginPage(){
        System.out.println("测试阶段");
        return "admin/login";
    }
    @RequestMapping("login01")
    public String  login(String username , String password, HttpSession session){
        System.out.println("username: "+username+ "   password : "+password);
        session.setAttribute("user",username);
//       比较并设置:
        if(username!=null&&!username.equals("")&&username.length()>0&&password!=null&&!password.equals("")&&password.length()>0){
            if(username.equals("admin")&&password.equals("123")){
                return  "admin/index";
            }
        }

        return "redirect:/admin/loginPage";
    }
    @ResponseBody
    @RequestMapping("/findAll")
    public List<People> findAll(){
        List<People> all = peopleService.findAll();
        System.out.println("all+++++++++++++++++"+all);
        System.out.println(all.get(0).getBlogs());
        return  all;
    }
    @RequestMapping("/toIndex")
    public String  toIndex(){
        return "admin/index";

    }
//


}
